package com.zelin.portal.web.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.zelin.content.service.ContentService;
import com.zelin.entity.ContentEntity;

import com.zelin.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * @author WF
 * @email 2568783935@qq.com
 * @date 2021-07-23 21:10:35
 */
@Controller
@RequestMapping
public class ContentController {
    @Reference(timeout = 5000)
    private ContentService contentService;
    /**
     * 功能: 1.查询所有的广告列表
     * 参数:
     * 返回值: java.lang.String
     * 时间: 2021/7/31 16:24
     */
    @RequestMapping({"/","/index.html"})
    public String findAll(Model model){
        List<ContentEntity> list = contentService.findAll();
        System.out.println("list = " + list);
        model.addAttribute("contents",list);
        return "index";
    }
    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @ResponseBody
    public R info(@PathVariable("id") Long id){
		ContentEntity content = contentService.getById(id);
        return R.ok().put("content", content);
    }
    /**
     * 保存
     */
    @RequestMapping("/save")
    @ResponseBody
    public R save(@RequestBody ContentEntity content){
		contentService.save(content);
        return R.ok();
    }
    /**
     * 修改
     */
    @RequestMapping("/update")
    @ResponseBody
    public R update(@RequestBody ContentEntity content){
		contentService.updateById(content);
        return R.ok();
    }
    /**
     * 删除
     */
    @RequestMapping("/delete")
    @ResponseBody
    public R delete(@RequestBody Long[] ids){
		contentService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
